define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'factor/index' + location.search,
                    add_url: 'factor/add',
                    edit_url: 'factor/edit',
                    del_url: 'factor/del',
                    multi_url: 'factor/multi',
                    dragsort_url:'',
                    table: 'factor',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'code', title: __('Code'), operate: 'LIKE'},
                        {field: 'expression', title: __('Expression'), operate: false},
                        {field: 'intro', title: __('Intro'), operate: 'LIKE'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'timu',
                                    classname: 'btn btn-xs   btn-dialog btn-reject',
                                    url: 'factor_config/index?factor_id={id}',
                                    text: '量表因子结果',
                                    extend: 'data-toggle="tooltip"  data-area=["100%","100%"]',
                                    visible: function (row) {
                                        return true;
                                    },
                                    title: function (row) {
                                        return '量表因子结果' + '-' + row.name;
                                    },
                                },

                            ]
                        }
                    ]
                ]
            });
         $(".search input").attr('placeholder','请输入搜索内容');
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
